/*
 * @Author: ChunLai
 * @Date: 2022-01-04 20:49:25
 * @LastEditTime: 2025-08-22 09:52:29
 * @Description: 网销版简易告知
 * @FilePath: \02.bldinsure\src\views\prenotice\simple\mixin.js
 */
import { mapGetters } from "vuex";

export const simpleMixin = {
  data() {
    return {
      pageData: [],
      notifyMsg: {},
      activeIndex: 0,
    };
  },
  computed: {
    ...mapGetters({
      workNum: "insert/workNum",
      orderNum: "insert/orderNum",
      showedRisks: "risks/showedRisks",
      bbrAutoHealthApi: "page/bbrAutoHealthApi",
      riskRelateNotice: "page/riskRelateNotice",
    }),
    isShareHealthy() {
      let res = false;
      if (this.$getDataFromUrl("share") == "1") {
        res = true;
      }
      return res;
    },
    tipMsg() {
      let res = `我已如实告知健康情况，并清楚知道若实际情况一告知内容不符，保险公司有权解除保险合同，且对保险合同解除前发生的事故，保险公司不承担赔偿或给付保险金责任。`;
      if (this.notifyMsg.topTip) {
        res = this.notifyMsg.topTip;
      }
      return res;
    },
    noticeLen() {
      let res = 0;
      if (this.pageData.length > 0) {
        res = this.pageData.length;
      }
      return res;
    },
    noticeObj() {
      let res = {};
      if (this.activeIndex <= this.noticeLen - 1) {
        res = this.pageData[this.activeIndex];
      }
      return res;
    },
  },
  methods: {
    initPageDatas() {
      this.pageLoad = false;
      this.$store.commit("updateLoad", true);
      let fileName = "simple";
      if (this.riskRelateNotice.length > 0) {
        const fdObj = this.riskRelateNotice.find((ele) =>
          ele.code.includes(this.mainRiskCode)
        );
        if (fdObj && fdObj.name) {
          fileName = fdObj.name;
        }
      }
      this.$store.dispatch("json/getNoticeJson", fileName).then((res) => {
        let { Datas, ...newObj } = res;
        const list = JSON.parse(JSON.stringify(Datas));
        this.pageData = list.filter((e) => {
          let flag = true;
          if (e.filterRisks) {
            const arr = this.showedRisks.filter((s) =>
              e.filterRisks.includes(s.varietyCode)
            );
            if (arr.length == 0) {
              flag = false;
            }
          }
          return flag;
        });
        this.notifyMsg = newObj;
        this.pageLoad = true;
        this.$store.commit("updateLoad", false);
      });
    },
    changeMd(idx) {
      if (idx > this.activeIndex) return;
      this.activeIndex = idx;
    },
  },
};
